<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>管理员管理</title>
	<link rel="stylesheet" href="/static/css/layui.css" />
	<link rel="stylesheet" href="/static/css/common.css" />
</head>

<body class="container">

	<div class="layui-card">
		<div class="layui-card-body">
			<table id="user-table" lay-filter="user-table"></table>
		</div>
	</div>


	<script type="text/html" id="del-bar">
		    <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="remove"><i class="layui-icon layui-icon-delete"></i></button>
		</script>


	<script src="/static/js/layui.js"></script>
	<script>
		layui.extend({
			api: '{/}/static/js/api' // 开头特定符 {/} 即代表采用单独路径
		}).use(['api'], function () {
			let table = layui.table;
			let form = layui.form;
			let $ = layui.jquery;
			let api = layui.api;
			let common = layui.common,
				req = api.req();

			let MODULE_PATH = "./";

			let cols = [
				[
					{
						title: '名称',
						field: 'name',
						align: 'center'
					},
					{
						title: '类型',
						field: 'type',
						align: 'center'
					},
					{
						title: '字段',
						field: 'fields',
						align: 'center'
					},

					{
						title: '操作',
						toolbar: '#del-bar',
						align: 'center',
						width: 80
					}
				]
			]

			table.render({
				elem: '#user-table',
				url: api.apiUrl + 'db/keysList?table=' + req.table,
				headers: api.getHeader(),
				parseData: function (res) {
					//console.log(res)
					return {
						"code": res.code, //解析接口状态
						"msg": res.message, //解析提示文本
						"count": res.data.count, //解析数据长度
						"data": res.data.list //解析数据列表
					};
				},
				page: true,
				cols: cols,
				skin: 'line'
			});

			table.on('tool(user-table)', function (obj) {
				if (obj.event === 'remove') {
					//window.remove(obj);
					layer.confirm('确定要删除该字段吗？', {
						icon: 3,
						title: '提示'
					}, function (index) {
						layer.close(index);
						let postdata = {
							table: req.table,
							name: obj.data.name
						}
						console.log(postdata)
						api.post('db/delKey', postdata, res => {
							layer.msg('删除成功', {
								icon: 1,
								time: 1000
							}, () => {
								obj.del();
								table.reload('user-table');
							});
						}, err => {

						})
					})

				}
			});
		})
	</script>
</body>

</html>